1. Field of the Invention
This invention is related to the field of processors and, more particularly, instruction execution in processors.
2. Description of the Related Art
Generally, computer systems execute software including application programs and an operating system. The application programs generally provide functionality to the user of the computer system. For example, application programs may include word processing programs, spreadsheets, financial software, circuit simulators, compilers, computer aided design (CAD) programs, circuit synthesis programs, desktop publishing programs, graphics design programs, internet browsers, email programs, etc. Numerous other examples of application programs may exist. The operating system, on the other hand, generally provides the low level interface to the computer hardware, insulating the application program from such details. Furthermore, modern operating systems provide for two or more application programs (or processes within the application programs, if the application programs are multi-threaded) to be active in the system concurrently. In such systems, the operating system manages allocation of computer system resources (e.g. allocating processor execution time to the active threads, as well as allocating memory and peripherals that may be included in the system) to the various active processes. Furthermore, the operating system may provide additional services that may be useful for a variety of application programs.
Since the application programs generally rely on the operating system for access to system resources and for other services, the application programs may include calls to various operating system routines to provide access to the resources or to provide a given service. Generally, the calling mechanism (which may include hardware features in the processor or processors in the computer system, software calling conventions, or a combination of both) includes an indication of the operating system routine being called (e.g. a variable indicating the requested service, an address of the operating system routine being called, etc.). Additionally, the calling mechanism provides some means for ensuring that the application program's data is preserved (including data stored in registers within the processor) and for establishing access to the operating system's data structures in the processor.
While much of the calling mechanism may be handled via software calling conventions (e.g. providing operands for the operating system routine in certain predefined registers or memory locations prior to executing a branch to the operating system routine, saving application registers by the application program prior to the call or after the call, etc.), establishing access to the operating system's data structures may be more complicated. Generally, the mechanism must ensure that the application program code does not get access to the operating system's privileged data structures. Additionally, the mechanism must supply, at some point, a pointer to the operating system's data structures. The mechanism for establishing access to the operating system's data structures may be complex and may be time consuming.
For example, the ×86 architecture specifies a mechanism for transferring control between privilege levels through the call/interrupt/trap gate mechanism (below referred to more succinctly as the gate mechanism). An application program is expected to execute at a low privilege level and the operating system, or a portion thereof, is expected to execute at a high privilege level. The gate mechanism uses gates in the segment tables to control entry into a higher privilege level, with a variety of protection checks being performed during the entry. Additionally, the gate mechanism provides for stack switching, saving the stack pointer for the application program and establishing a stack pointer (in the stack pointer register, or ESP) to a stack used by the higher privileged code (e.g. the operating system routine). Using this mechanism, a pointer to the operating system's stack may be established. The stack may be used to store pointers to other operating system data structures, thus allowing the operating system routine to access any desired data structures. The gate mechanism is relatively slow, typically requiring on the order of hundreds of processor clocks to operate.
An additional mechanism for performing operating system calls in the ×86 architecture are the Syscall and Sysret instructions defined by Advanced Micro Devices, Inc. These instructions provide a rapid transfer to the operating system routine. However, these instructions do not provide a mechanism for providing access to operating system data structures.